//
//  AttachmentInfoDelegate.m
//  cTypica
//
//  Created by David Kavanagh on 2/16/09.
//  Copyright 2009 directThought. All rights reserved.
//

#import "AttachmentInfoDelegate.h"


@implementation AttachmentInfoDelegate
@synthesize attachmentInfo, formatter;

+ (id)delegate {
	AttachmentInfoDelegate *ret = [self alloc];
	ret.formatter = [[NSDateFormatter alloc] init];
	[ret.formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
	return ret;
}

- (void) dealloc {
	[formatter release];
	[super dealloc];
}

// XML parser delegate methods
- (void)parser: (NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
	if ([elementName isEqualToString:@"AttachVolumeResponse"]) {
		self.attachmentInfo = [AttachmentInfo alloc];
	}
}

- (void)parser: (NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
	NSString *cleanString = [currentStringValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
	[currentStringValue setString:@""];
	if ([elementName isEqualToString:@"volumeId"]) {
		attachmentInfo.volumeId = cleanString;
	}
	else if ([elementName isEqualToString:@"status"]) {
		attachmentInfo.status = cleanString;
	}
	else if ([elementName isEqualToString:@"instanceId"]) {
		attachmentInfo.instanceId = cleanString;
	}
	else if ([elementName isEqualToString:@"device"]) {
		attachmentInfo.device = cleanString;
	}
	else if ([elementName isEqualToString:@"attachTime"]) {
		attachmentInfo.attachTime = [formatter dateFromString:cleanString];
		//[cleanString release];
	}
}
@end
